package com.ScoresSystem.controller;

import com.ScoresSystem.utils.Result;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/user")
public class UserController {

    @GetMapping("/getNowUserName")
    @ResponseBody
    public Result<String> getNowUserName(HttpSession session){
        Object name = session.getAttribute("nowusername");
        if(name!=null){
            return new Result<>("0", "获取成功", name.toString());
        }
        return new Result<>("1", "获取失败", "");
    }

    @PostMapping("/loginOut")
    @ResponseBody
    public Result<String> loginOut(HttpSession session){
        session.removeAttribute("nowusername");
        return new Result<>("0", "退出成功");
    }

}